import java.util.Arrays;

public class TestMerge {
    public static void main(String[] args) {
        int[] nums1 = {1,2,3};
        int[] nums2 = {2,5,6};
        int m = 3,n = 3;
        //2.扩容nums1
        int[] tmp = new int[m+n];
        System.arraycopy(nums1,0,tmp,0,m);
        nums1 = tmp;

        merge(nums1,m,nums2,n);
        for (int x : nums1) {
            System.out.print(x+" ");
        }
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        for (int i = 0; i != n; ++i) {
            nums1[m + i] = nums2[i]; //1.此时nums1[m + i]会报数组下标越界，我们需要提前扩容nums1
        }
        Arrays.sort(nums1);
    }
}
